<template>
  <div class="page-box">
    <div class="page-header">
      <div class="back" @click="goback">
        <el-icon><ArrowLeftBold /></el-icon>
      </div>
      <div class="title">订单详情</div>
    </div>
    <div class="content-box">
      <div class="order-status">
        {{ orderStatusEnum[orderDetail.status] }}
      </div>
      <div class="goods-list">
        <template v-for="(goodsItem, goodsIndex) in orderDetail.list" :key="goodsIndex">
          <div class="goods-item">
            <div class="goods-img">
              <img :src="goodsItem.picGoodsUrl" class="goods-pic" />
            </div>
            <div class="item-content">
              <div class="goods-title">
                {{ goodsItem.menuName }}
              </div>
              <div class="goods-info">
                <div class="goods-num">x {{ goodsItem.quantity }}</div>
                <div class="goods-price">￥{{ (goodsItem.price / 100).toFixed(2) }}</div>
              </div>
            </div>
          </div>
        </template>
      </div>
      <div class="price">
        <span>
          <span>总计：</span>
          <span>￥{{ (orderDetail.totalAmount / 100).toFixed(2) }}</span>
        </span>
      </div>
    </div>
    <div class="content-box" style="margin-top: 12px">
      <div class="row">
        <div class="item-title">订单号：</div>
        <div class="item-content">
          {{ orderDetail.orderNo ? orderDetail.orderNo : "--" }}
        </div>
      </div>
      <div class="row">
        <div class="item-title">下单时间：</div>
        <div class="item-content">
          {{ orderDetail.orderTime ? dayjs(orderDetail.orderTime * 1000).format("YYYY-MM-DD HH:mm:ss") : "--" }}
        </div>
      </div>
      <div class="row">
        <div class="item-title">支付时间：</div>
        <div class="item-content">
          {{ orderDetail.paymentTime ? dayjs(orderDetail.paymentTime * 1000).format("YYYY-MM-DD HH:mm:ss") : "--" }}
        </div>
      </div>
      <div class="row">
        <div class="item-title">餐桌号：</div>
        <div class="item-content">
          {{ orderDetail.tableId ? orderDetail.tableId : "--" }}
        </div>
      </div>
    </div>
    <template v-for="(commentItem, commentIndex) in commentList" :key="commentIndex">
      <div class="content-box" style="margin-top: 12px">
        <div class="title">评论信息</div>
        <div class="content">{{ commentItem.comment }}</div>
        <div class="stars">
          <div>评价得分</div>
          <div class="stars-list">
            <template v-for="(item, index) in 5" :key="index">
              <template v-if="commentItem.rating > index">
                <img src="../home/images/like-2.png" />
              </template>
              <template v-else>
                <img src="../home/images/like-1.png" />
              </template>
            </template>
          </div>
        </div>
      </div>
    </template>
  </div>
</template>
<script setup lang="ts">
import { ref, onMounted } from "vue";
import { getOrderDetail, getCommentDetail } from "@/api/modules/mobile";
import dayjs from "dayjs";
import { useRoute, useRouter } from "vue-router";
const route = useRoute();
const router = useRouter();

const orderStatusEnum = ["--", "待支付", "已支付", "已取消", "已退款"];

const orderDetail = ref<any>({});

const commentList = ref<any[]>([]);
onMounted(async () => {
  const query = route.query;
  if (query.orderId) {
    const params = { orderId: query.orderId };
    const res = await getOrderDetail(params);
    if (res) {
      orderDetail.value = res.data;
    }
    const res2 = await getCommentDetail(params);
    commentList.value = res2.data.list || [];
  }
});

const goback = () => {
  router.go(-1);
};
</script>

<style lang="scss" scoped>
.page-box {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: #f3f0f0;
  .page-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 40px;
    background-color: #ffffff;
    border-bottom: 1px solid #333333;
    .back {
      position: absolute;
      top: 12px;
      left: 12px;
    }
  }
  .page-content {
    width: 100%;
    height: calc(100% - 60px);
    background-color: #f3f0f0;
  }
  .content-box {
    width: calc(100% - 56px);
    height: auto;
    padding: 12px;
    margin: 16px 16px 0;
    font-size: 13px;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 5px 1px #33333350;
    .order-status {
      width: 100%;
      text-align: right;
    }
    .goods-list {
      display: flex;
      flex-direction: column;
      width: 100%;
      .goods-item {
        display: flex;
        width: calc(100% - 24px);
        padding: 12px;
        border-bottom: 1px solid #eeeeee;
        .goods-img {
          width: 60px;
          height: 60px;
          background-color: #eeeeee;
          img {
            width: 100%;
            height: 100%;
          }
        }
        .item-content {
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          width: calc(100% - 72px);
          margin-left: 12px;
          .goods-title {
            font-size: 14px;
          }
          .goods-info {
            display: flex;
            justify-content: space-between;
            width: 100%;
            height: auto;
          }
        }
      }
    }
    .price {
      width: 100%;
      margin-top: 12px;
      font-size: 16px;
      text-align: right;
    }
    .row {
      display: flex;
      justify-content: space-between;
      width: 100%;
      margin: 8px 0;
      font-size: 14px;
    }
    .title {
      width: 100%;
      margin-bottom: 12px;
      font-size: 14px;
    }
    .content {
      width: 100%;
      margin-bottom: 12px;
      font-size: 14px;
    }
    .stars {
      display: flex;
      justify-content: space-between;
      width: 100%;
      font-size: 14px;
      .stars-list {
        display: flex;
        width: auto;
        img {
          width: 24px;
          height: 24px;
          margin-left: 4px;
        }
      }
    }
  }
}
</style>
